"""
Storage 模块 - 业务文件关联模型
"""
from sqlalchemy import Column, String, Integer, JSON, BigInteger
from sqlalchemy.orm import Mapped, mapped_column
from axiom_boot.core.types import BigInt
from axiom_boot.database.base_model import BaseModel


class SysFileBusinessRelation(BaseModel):
    """业务文件关联表 - 通用设计，管理任意业务数据与文件的关联关系"""
    
    __tablename__ = 'sys_file_business_relation'
    
    # 显式重写 id 以符合【主键覆盖原则】
    id: Mapped[BigInt] = mapped_column(BigInteger, primary_key=True, comment="主键ID (雪花ID)")
    
    # 关联信息 - 通用设计
    business_type = Column(String(50), nullable=False, comment='业务类型(vehicle/product/article等)')
    business_id = Column(BigInteger, nullable=False, comment='业务记录的唯一标识ID')
    file_id = Column(BigInteger, nullable=False, comment='文件ID(对应sys_file_storage.id)')
    
    # 关联详细信息
    relation_type = Column(String(30), nullable=False, comment='关联类型(image/document/video/audio等)')
    file_category = Column(String(30), comment='文件分类(small/large/thumbnail/original等)')
    sort_order = Column(Integer, default=0, comment='排序序号')
    is_primary = Column(Integer, default=0, comment='是否主要文件(0-否, 1-是)')
    
    # 业务扩展字段
    extra_data = Column(JSON, comment='扩展数据(根据具体业务需求存储额外信息)')
    remark = Column(String(500), comment='备注说明')
    
    def __repr__(self):
        return f"<SysFileBusinessRelation(business_type='{self.business_type}', " \
               f"business_id='{self.business_id}', file_id={self.file_id})>"
